home *** CD-ROM | disk | FTP | other *** search
/ A Teacher's Guide to the Holocaust / A Teacher's Guide to the Holocaust.iso / data / people / scripts / cmi.js < prev    next >
Text File  |  1999-12-05  |  6KB  |  222 lines

  1. // Copyright 1998 Macromedia, Inc. All rights reserved.
  2.  
  3. var MM_SID="", MM_TURL="", MM_CMIDOC="", aicd = "aicc_data", co = "[core]", ls="Lesson_Status", cmnd="command", cmdArray;
  4. var IE3 = ((navigator.appName.indexOf("Microsoft") != -1) && (parseFloat(navigator.appVersion) < 3));
  5. if (window.cmdQueue == null)
  6.   window.cmdQueue = new CmdQueue()
  7.  
  8. function CmdQueue() {
  9.   this.cmd = new Array();
  10.   this.cmdData = new Array();
  11.   this.sIDs = new Array();
  12.   this.qLen = 0;  
  13.   this.latency = (navigator.appName.indexOf('Microsoft') != -1)?1250:1000;
  14.   this.addCmd = cmdQAddCmd;
  15.   this.delCmd = cmdQDelCmd;  
  16. }
  17.  
  18. function cmdQAddCmd(command, sid, cmddata) {
  19.   this.cmd[this.qLen] = command;
  20.   this.sIDs[this.qLen] = sid;
  21.   this.cmdData[this.qLen] = cmddata;
  22.   this.qLen++;
  23.   if (this.qLen == 1) { 
  24.     if (!IE3 && (window.CmdSubmit == null))
  25.       window.CmdSubmit = CmdSubmit; 
  26.     setTimeout("CmdSubmit()", this.latency); 
  27.   }
  28. }
  29.  
  30. function cmdQDelCmd() {
  31.   var i, len;
  32.   if (this.qLen == 0) return;
  33.   else if (this.qLen == 1)
  34.     this.cmd.length = this.sIDs.length = this.cmdData.length = 0;
  35.   else {
  36.     for (i=1, len=this.qLen; i<len; i++) {
  37.       this.cmd[i-1] = this.cmd[i];
  38.       this.sIDs[i-1] = this.sIDs[i];
  39.       this.cmdData[i-1] = this.cmdData[i];
  40.     }
  41.     this.cmd.length = this.sIDs.length = this.cmdData.length = this.qLen - 1;
  42.   }
  43.   this.qLen--;
  44. }
  45.  
  46. function CmdSubmit() {
  47.     document.command.elements[cmnd].value = cmdQueue.cmd[0];
  48.     document.command.elements[aicd].value = cmdQueue.cmdData[0];
  49.     document.command.elements["session_id"].value = cmdQueue.sIDs[0];
  50.     document.command.submit();
  51.     cmdQueue.delCmd();
  52.     if (cmdQueue.qLen >= 1) {
  53.       if (!IE3) window.CmdSubmit = CmdSubmit;
  54.       setTimeout("CmdSubmit()", cmdQueue.latency);
  55.     }
  56. }
  57.  
  58. function MM_SGet() {document.command.elements["command"].value = "getparam";}
  59. function MM_SPut() {document.command.elements["command"].value = "putparam";}
  60. function MM_SPInt() {document.command.elements["command"].value = "putinteractions";}
  61.  
  62. function MM_SVal(idx, val0, sub) {
  63.   document.command.elements[idx].value=val0;
  64.   if (sub) MM_Sub();
  65. }
  66. function MM_ApndVal(val0) {document.command.elements[aicd].value += '\r\n'+val0;}
  67.  
  68. function MM_Sub() {
  69.   if (MM_SID.length > 0) {
  70.     var frm = document.command;
  71.     cmdQueue.addCmd(frm.elements[cmnd].value,MM_SID,frm.elements[aicd].value);
  72.   }
  73. }
  74.  
  75. function MM_CMISetParms(url) {
  76.   var prms="", tmpp;  
  77.   pos=url.indexOf("#")
  78.   if (pos==-1) pos=url.indexOf("?")
  79.   if (pos>-1) prms=url.substring(pos+1,url.length)
  80.   tmpp=prms.toUpperCase()
  81.   if (tmpp.indexOf("AICC-SID")>-1) {
  82.     alert("Lesson Server version incompatible.  Your administrator must upgrade to the latest version.");
  83.     return false;
  84.   }
  85.   if ((pos=tmpp.indexOf("AICC_SID="))>-1) {
  86.     MM_SID=prms.substring(pos+8,prms.length)
  87.     if (MM_SID.indexOf("&")>0)
  88.       MM_SID=unescape(MM_SID.substring(1,MM_SID.indexOf("&")))
  89.   }
  90.   if ((pos=tmpp.indexOf("AICC_URL"))>-1) {
  91.     MM_TURL=prms.substring(pos+9,prms.length)
  92.     if (MM_TURL.indexOf("&")>0)
  93.       MM_TURL=MM_TURL.substring(1,MM_TURL.indexOf("&"))
  94.     MM_TURL=unescape(MM_TURL)
  95.   }
  96.   return (MM_TURL=="" || MM_SID=="")?false:true;  
  97. }
  98.  
  99. function findcmidocument(win) { 
  100.   if (MM_CMISetParms(win.document.location+"") == false) {
  101.     if (win == window.top) return null
  102.     return findcmidocument(win.parent)
  103.   } else {
  104.     MM_CMIDOC = win.document;
  105.     return win.document;
  106.   }
  107.  
  108. function cmiinit(win) {
  109.   frm=findcmiframe(null);
  110.   if (frm!=null)
  111.    frm.installcmi(win);
  112.   findcmidocument(win);
  113.   window.CMITURL = MM_TURL;
  114.   return CMIIsPresent();
  115. }
  116.  
  117. function CMIInitialize() {
  118.   if ((MM_CMIDOC!=null) && (MM_CMIDOC.length!=0)){  
  119.     MM_SVal("session_id",MM_SID);
  120.     retVal = true;
  121.   } else retVal = false;
  122.   return retVal;
  123. }
  124.  
  125. function CMIIsPresent() {
  126.   return MM_SID.length != 0;
  127. }
  128.  
  129. function CMIAddInteraction(date, time, intid, objid, intrtype, correct, student, result, weight, latency) {
  130.   MM_SVal("command","putinteractions")
  131.   MM_SVal(aicd,'"date", "time", "interaction_id", "objective_id", "type_interaction", "correct_response", "student_response", "result", "weighting", "latency"\r\n' +
  132.     '"' + date + '", ' +
  133.     '"' + time + '", ' +
  134.     '"' + intid + '", ' +
  135.     '"' + objid + '", ' +
  136.     '"' + intrtype + '", ' +
  137.     '"' + correct + '", ' +
  138.     '"' + student + '", ' +
  139.     '"' + result + '", ' +
  140.     '"' + weight + '", ' +
  141.     '"' + latency+ '"',1);
  142. }
  143.  
  144. function CMISetCompleted() { CMISetStatus("C"); }
  145.  
  146. function CMISetData(data) {
  147.   MM_SPut()
  148.   MM_SVal(aicd,"[Core_Lesson]\r\n"+data,1)
  149. }
  150.  
  151. function CMISetFailed() { CMISetStatus("F"); }
  152.  
  153. function CMISetLocation(loc) {
  154.   MM_SPut()
  155.   MM_SVal(aicd,co+"\r\nLesson_Location="+loc,1)
  156. }
  157.  
  158. function CMISetObj(index, id, score, status, started, completed, passed, failed) {
  159.   MM_SPut()
  160.   MM_SVal(aicd,"[Objectives_Status]\r\nJ_ID."+index+"="+id)
  161.   // if objective info isn't there already need to write a not-started flag
  162.   if (status=="")
  163.     MM_ApndVal("J_STATUS."+index+"="+started?'I':completed?'C':passed?'P':'F');
  164.   else 
  165.     MM_ApndVal("J_STATUS."+index+"="+status); 
  166.   MM_ApndVal("J_SCORE."+index+"="+score);
  167.   MM_Sub();
  168. }
  169.  
  170. function CMISetPassed() { CMISetStatus("P"); }
  171.  
  172. function CMISetScore(score) { 
  173.   MM_SPut()
  174.   MM_SVal(aicd,co+"\r\nscore="+score,1)
  175. }
  176.  
  177. function CMISetStarted() { CMISetStatus("I"); }
  178.  
  179. function CMISetStatus(stat) {
  180.   MM_SPut()
  181.   MM_SVal(aicd,co+"\r\n"+ls+"="+stat,1)
  182. }
  183.  
  184. function CMISetTime(t) {
  185.   var x=3600;
  186.   var y=60;
  187.   var h=Math.round(t/x - t%x/x)+'';
  188.   var m=Math.round((t-h*x)/y-(t-h*x)%y/y)+'';
  189.   var s=Math.round(t-h*x-m*y)+'';
  190.   if (h.toString().length == 1) h='0'+h;
  191.   if (m.toString().length == 1) m='0'+m;
  192.   if (s.toString().length == 1) s='0'+s;
  193.   MM_SPut()
  194.   MM_SVal(aicd,co+"\r\nTime="+h+":"+m+":"+s,1)
  195. }
  196.  
  197. function CMISetTimedOut() {
  198.   MM_SPut()
  199.   MM_SVal(aicd,co+"\r\n"+ls+"=incomplete,time-out",1)
  200. }
  201.  
  202. function installcmi(win) {
  203.   if ((win.CMIInitialize == null) && !IE3) {
  204.     win.CMIInitialize = CMIInitialize;
  205.     win.CMIIsPresent = CMIIsPresent;
  206.     win.CMIAddInteraction =CMIAddInteraction
  207.     win.CMISetCompleted =CMISetCompleted
  208.     win.CMISetData =CMISetData
  209.     win.CMISetFailed =CMISetFailed
  210.     win.CMISetLocation =CMISetLocation
  211.     win.CMISetObj =CMISetObj
  212.     win.CMISetPassed =CMISetPassed
  213.     win.CMISetScore =CMISetScore
  214.     win.CMISetStarted =CMISetStarted
  215.     win.CMISetStatus =CMISetStatus
  216.     win.CMISetTime =CMISetTime
  217.     win.CMISetTimedOut =CMISetTimedOut
  218.     win.CMITURL = MM_TURL
  219.   }
  220. }
  221.